package com.jprocms.module.cms.api.dto;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Set;

import static com.jprocms.module.cms.constant.CmsSysConstants.SUFFIX;

/**
 * @author jprocms
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Schema(description = "管理后台 - 站点配置默认模板 Request VO")
public class SiteDefTplDto {

    @Schema(description = "id")
    private Long id;

    @Schema(description = "pc模板方案")
    @NotNull(message = "pc模板方案不能为空")
    private String pcSolution;

    @Schema(description = "h5模板方案")
    @NotNull(message = "h5模板方案不能为空")
    private String h5Solution;

    @Schema(description = "站点ID")
    private Long siteId;

    @NotNull
    @Schema(description = "发布平台ID")
    private Long platformId;

    @Schema(description = "首页模板")
    private String indexTpl;

    @Schema(description = "列表模板")
    private String defListTpl;

    public void setIndexTpl(String indexTpl) {
        if (StringUtils.endsWithIgnoreCase(indexTpl, SUFFIX)) {
            indexTpl = indexTpl.substring(0, indexTpl.lastIndexOf(SUFFIX));
        }
        this.indexTpl = indexTpl;
    }

    public void setDefListTpl(String defListTpl) {
        if (StringUtils.endsWithIgnoreCase(defListTpl, SUFFIX)) {
            defListTpl = defListTpl.substring(0, defListTpl.lastIndexOf(SUFFIX));
        }
        this.defListTpl = defListTpl;
    }

    @Schema(description = "内容详情模板")
    @Valid
    private Set<SiteContentDefTplDto> contentDefTpls;

}
